package com.hc.acoustics.widget;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager.LayoutParams;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.DrawableRes;

import com.hc.acoustics.R;
import com.yc.yclibx.file.YcImgUtils;

/**
 * 显示图片用的对话框
 */
public class ShowImageDialog extends Dialog {
    private ImageView mIv;
    private ImageView mCloseIv;
    private TextView mMsgTv;
    private String mCopyMsg;

    public ShowImageDialog(Context context) {
        this(context, R.style.CommonDialogStyle);
    }

    public ShowImageDialog(Context context, int theme) {
        super(context, theme);
        initViews(context);
    }

    private void initViews(final Context context) {
        setContentView(R.layout.widget_dialog);
        mCloseIv = (ImageView) findViewById(R.id.dialogCloseIv);
        mIv = (ImageView) findViewById(R.id.dialogIv);
        mMsgTv = (TextView) findViewById(R.id.dialogMsgTv);
        //设置对话框位置大小
        Window dialogWindow = getWindow();
        dialogWindow.setGravity(Gravity.CENTER);
        dialogWindow.setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        setCanceledOnTouchOutside(false);
        setCancelable(false);
        mCloseIv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        mMsgTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (CopyUtils.copy(mCopyMsg, context)) {
                    Toast.makeText(context, "复制成功", Toast.LENGTH_LONG).show();
                } else {
                    Toast.makeText(context, "无法复制", Toast.LENGTH_LONG).show();
                }
            }
        });

//        mIv.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                dismiss();
//            }
//        });
    }

    public ShowImageDialog setImageResource(@DrawableRes int resId) {
        YcImgUtils.loadResIdImg(getContext(), resId, mIv);
        return this;
    }


    public ShowImageDialog setMessage(String showMsg) {
        mMsgTv.setText(showMsg);
        return this;
    }

    public ShowImageDialog setCopyMsg(String copyMsg) {
        mCopyMsg = copyMsg;
        return this;
    }
}
